package com.cmccgz.udacs_landlord_webapp.main.peoplemanager.presenter;

import com.cmccgz.udacs_landlord_webapp.base.ApiService;
import com.cmccgz.udacs_landlord_webapp.bean.CardMsg;
import com.cmccgz.udacs_landlord_webapp.bean.ExchangeCard;
import com.cmccgz.udacs_landlord_webapp.bean.ResultBean;
import com.cmccgz.udacs_landlord_webapp.main.peoplemanager.contract.ExchangeContract;

import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author Denis
 * @ClassName: DelayPresenter
 * @Description: 换卡界面
 * @date 2017/6/7 14:37
 */

public class ExchangePresenter implements ExchangeContract.Presenter {
    private ExchangeContract.View view;

    public ExchangePresenter(ExchangeContract.View view) {
        this.view = view;
        view.setPresenter(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void exChangeCard(String user_mobile, String house_id, List<ExchangeCard> cards) {
        Subscriber<ResultBean<String>> subscriber = new Subscriber<ResultBean<String>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(ResultBean<String> stringResultBean) {
                view.exChangeCardSucce(stringResultBean.rsmsg.rscode);
            }
        };
        ApiService.changeCard(user_mobile, house_id, cards)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    @Override
    public void getCardMsg(String user_mobile, String house_id) {
        Subscriber<ResultBean<CardMsg>> subscriber = new Subscriber<ResultBean<CardMsg>>() {
            @Override
            public void onStart() {
                view.loadingData();
            }

            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                view.finishGetData(null);
            }

            @Override
            public void onNext(ResultBean<CardMsg> cardMsgResultBean) {
                view.finishGetData(cardMsgResultBean.resp);

            }
        };
        ApiService.getCardDetail(user_mobile, house_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }
}
